home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickTime / Programming Stuff / Sample Code / Music Architecture / Embedding Instruments / BigEasy / BigEasyGrafish.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  5.1 KB  |  316 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        BigEasyGrafish.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    xxx put writers here xxx
  7.  
  8.     Copyright:    © 1991, 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     This file is used in these builds: Warhol
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <6>      9-8-94    dvb        
  15.          <4>     1/20/92    dvb        Add more routines.
  16.          <3>     5/23/91    PH        changes for THINK 5
  17.          <2>     4/25/91    JB        Changing to new THINK_C interface files
  18.  
  19.     To Do:
  20. */
  21.  
  22. /* file: BigEasyGrafish.c
  23.  *
  24.  * Started 4 August 1989, more or less.
  25.  *
  26.  * A set of routines for doing certain
  27.  * QuickDraw like operations on the Macintosh.
  28.  *
  29.  */
  30.  
  31.  
  32.  
  33. /*--------------------------------
  34.     Inclusions
  35. --------------------------------*/
  36.  
  37. #include <QuickDraw.h>
  38. #include <Resources.h>
  39. #include <Memory.h>
  40. #include <Palettes.h>
  41. #include <GestaltEqu.h>
  42.  
  43. #define BigEasyGrafish
  44.  
  45. #include "BigEasyGrafish.h"
  46.  
  47.  
  48. /*--------------------------------
  49.     Data
  50. --------------------------------*/
  51.  
  52. unsigned char dGrayPat[] = {0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA};
  53. unsigned char dBlackPat[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
  54.  
  55.  
  56. /*--------------------------------
  57.     Local Variables & Routines
  58. --------------------------------*/
  59.  
  60. static Boolean GestaltColor(void);
  61. static Boolean gBEGHasColor;
  62. static Boolean gDoneColorGestalt = false;
  63.  
  64.  
  65. /*--------------------------------
  66.     Routines
  67. --------------------------------*/
  68.  
  69. void RGBFore(unsigned short r,unsigned short g,unsigned short b)
  70.     {
  71.     GestaltColor();
  72.     if(gBEGHasColor || 1)
  73.         {
  74.         RGBColor c;
  75.  
  76.         c.red = r;
  77.         c.green = g;
  78.         c.blue = b;
  79.         RGBForeColor(&c);
  80.         }
  81.     else
  82.         {
  83.         unsigned long x;
  84.  
  85.         x = r + g + b;
  86.         if ( x > (3 * 32768))
  87.             ForeColor(whiteColor);
  88.         else
  89.             ForeColor(blackColor);
  90.         }
  91.     }
  92.  
  93. void RGBBack(unsigned short r,unsigned short g,unsigned short b)
  94.     {
  95.     GestaltColor();
  96.     if(gBEGHasColor || 1)
  97.         {
  98.         RGBColor c;
  99.  
  100.         c.red = r;
  101.         c.green = g;
  102.         c.blue = b;
  103.         RGBBackColor(&c);
  104.         }
  105.     else
  106.         {
  107.         unsigned long x;
  108.  
  109.         x = r + g + b;
  110.         if ( x > (3 * 32768))
  111.             BackColor(whiteColor);
  112.         else
  113.             BackColor(blackColor);
  114.         }
  115.     }
  116.  
  117. void GoWhite()
  118.     {
  119.     PenPat((Pattern *)dBlackPat);
  120.     ForeColor(whiteColor);
  121.     }
  122.  
  123. void GoGray()
  124.     {
  125.     PenPat((Pattern *)dBlackPat);
  126.     RGBFore(32768,32768,32768);
  127.     }
  128.  
  129. void GoBlack()
  130.     {
  131.     PenPat((Pattern *)dBlackPat);
  132.     ForeColor(blackColor);
  133.     }
  134.  
  135. void GoBW()
  136.     {
  137.     PenNormal();
  138.     ForeColor(blackColor);
  139.     BackColor(whiteColor);
  140.     }
  141.  
  142. void RGBOp(unsigned short r,unsigned short g,unsigned short b)
  143.     {
  144.     RGBColor c;
  145.     c.red = r;
  146.     c.green = g;
  147.     c.blue = b;
  148.     OpColor(&c);
  149.     }
  150.  
  151. void RGBHilite(unsigned short r,unsigned short g,unsigned short b)
  152.     {
  153.     RGBColor c;
  154.     c.red = r;
  155.     c.green = g;
  156.     c.blue = b;
  157.     HiliteColor(&c);
  158.     }
  159.  
  160. void PmHilite(short h)
  161.     {
  162.     PaletteHandle ph;
  163.     RGBColor c;
  164.  
  165.     ph = GetPalette(FrontWindow());
  166.     GetEntryColor(ph,h,&c);
  167.     HiliteColor(&c);
  168.     }
  169.  
  170.  
  171.  
  172. void RampColorTable(CTabHandle ctH,short start,short length,
  173.         unsigned short r1,unsigned short g1,unsigned short b1,
  174.         unsigned short r2,unsigned short g2,unsigned short b2)
  175. /*
  176.   * Make an rgb ramp in the color table handle passed.
  177.   */
  178.     {
  179.     long dr,dg,db;
  180.     short i;
  181.     ColorSpec *c;
  182.  
  183.     dr = r2-r1;
  184.     dg = g2-g1;
  185.     db = b2-b1;
  186.  
  187.     c = &(**ctH).ctTable[start];
  188.     for(i = 0; i< length; i++)
  189.         {
  190.         c->value = start+i;
  191.         c->rgb.red = r1+ dr*i/length;
  192.         c->rgb.green = g1+ dg*i/length;
  193.         c->rgb.blue = b1+ db*i/length;
  194.         c++;
  195.         }
  196.     }
  197.     
  198. void FrameRectOutside(Rect *r)
  199.     {
  200.     Rect r2;
  201.     PenState ps;
  202.  
  203.     r2 = *r;
  204.     GetPenState(&ps);
  205.     InsetRect(&r2,-ps.pnSize.h,-ps.pnSize.v);
  206.     FrameRect(&r2);
  207.     }
  208.  
  209. void DrawIcl8Resource(short id,Rect *r)
  210. /*
  211.  * Draw the icl8, disregarding masks and such
  212.  */
  213.     {
  214.     PixMap pm;
  215.     Handle h;
  216.  
  217.     h = GetResource('icl8',id);
  218.     if(!h)
  219.         {
  220.         PaintRect(r);
  221.         return;
  222.         }
  223.  
  224.     HLock(h);
  225.  
  226.     pm.baseAddr = *h;
  227.     pm.rowBytes = 32 | 0x8000;
  228.     pm.bounds.top = pm.bounds.left = 0;
  229.     pm.bounds.bottom = pm.bounds.right = 32;
  230.     pm.pmVersion = 0;
  231.     pm.packType = 0;
  232.     pm.packSize = 0;
  233.     pm.hRes = pm.vRes = 0x00480000;
  234.     pm.pixelType = 0;
  235.     pm.pixelSize = 8;
  236.     pm.cmpCount = 1;
  237.     pm.cmpSize = 8;
  238.     pm.planeBytes = 0;
  239.     pm.pmTable = GetCTable(8);
  240.     pm.pmReserved = 0;
  241.  
  242.     CopyBits((void *)&pm,&qd.thePort->portBits,&pm.bounds,r,0,0);
  243.  
  244.     DisposeCTable(pm.pmTable);
  245.     HUnlock(h);
  246.     ReleaseResource(h);
  247.     }
  248.  
  249.  
  250. Boolean EasyHasColor(void)
  251. /*
  252.  * In a nutshell: returns True of the
  253.  * 0,0-point of the current port is
  254.  * anything besides a b/w situation.
  255.  */
  256.     {
  257.     GDHandle gdH;
  258.     Rect r;
  259.     Boolean b;
  260.  
  261.     if(GestaltColor)
  262.         {
  263.         r = qd.thePort->portRect;
  264.         LocalToGlobal((Point *)&r.top);
  265.         LocalToGlobal((Point *)&r.bottom);
  266.         gdH = GetMaxDevice(&r);
  267.         if(gdH)
  268.             b = (**(**gdH).gdPMap).pixelSize > 1;
  269.         else
  270.             b = false;        /* not on any device... whatever */
  271.         }
  272.     else
  273.         b = false;
  274.  
  275.     return b;
  276.     }
  277.  
  278.  
  279. Boolean GestaltColor(void)
  280.     {
  281.     long result;
  282.  
  283.     if(!gDoneColorGestalt)
  284.         gBEGHasColor = (Gestalt('qdrw',&result)) ?
  285.                 false : (result & (1<<gestaltHasDeepGWorlds)) != 0;
  286.  
  287.     return gBEGHasColor;
  288.     }
  289.  
  290. void DrawPixMap(PixMap *pm,Rect *src,Rect *dst,short mode)
  291.     {
  292.     Rect srcR,dstR;
  293.  
  294.     if(src)
  295.         srcR = *src;
  296.     else
  297.         srcR = pm->bounds;
  298.  
  299.     if(dst)
  300.         dstR = *dst;
  301.     else
  302.         dstR = srcR;
  303.  
  304.     CopyBits((BitMap *)pm,&qd.thePort->portBits,&srcR,&dstR,mode,nil);
  305.     }
  306.  
  307. void DrawPixMapOffset(PixMap *pm,short x,short y,short mode)
  308.     {
  309.     Rect r;
  310.  
  311.     r = pm->bounds;
  312.     OffsetRect(&r,x,y);
  313.     DrawPixMap(pm,nil,&r,mode);
  314.     }
  315.  
  316.